package com.wanxi.config;

import com.wanxi.dto.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Li
 * @Date 2023/7/26 19:51
 */
@Configuration
public class RabbitConfig {
Logger logger = LoggerFactory.getLogger(com.wanxi.config.RabbitConfig.class.getName());

    /**
     * 创建交换机
     * @return
     */
    @Bean
    TopicExchange topicExchange(){
        logger.info("rabbit_mq_exchange |> 交换机创建成功！");
        return new TopicExchange(Constant.MQ_EXCHANGE,true,false);
    }

    /**
     *    创建消息队列
     * @return
     */
    @Bean
    Queue topicQueue(){
     logger.info("rabbit_mq_queue |> 创建消息成功！");
        return new Queue(Constant.MQ_QUEUE,true);
    }

    /**
     * 绑定消息队列到交换机
     * @return
     */
    @Bean
    Binding bindExchangeQueue(){
        logger.info("binding key：wx.# |> 绑定成功!");
      return   BindingBuilder.bind(topicQueue()).to(topicExchange()).with(Constant.MQ_BINDING_KEY);
    }
}
